package com.lyd.management.controller;


import com.lyd.management.util.AlipayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class AlipayController {


    private AlipayUtil alipayUtil;

    @Autowired
    public void setAlipayUtil(AlipayUtil alipayUtil) {
        this.alipayUtil = alipayUtil;
    }

    @RequestMapping("/pay")
    public String index(){
        return "index";
  }

  @PostMapping("/create")
  public String create(String id, String price, String title, Model model) {
        String pay = alipayUtil.pay(id, price, title);
        model.addAttribute("form",pay);
        return "pay";
  }

  @GetMapping("/return")
  public String returnNotice(String out_trade_no,Model model){
        String query = alipayUtil.query(out_trade_no);
        model.addAttribute("query",query);
        return "query";
    }

    @PostMapping("/notify")
    public  void notifyinfo(String trade_no,String total_amount,String trade_status,String notify_time){
        System.err.println("订单编号："+trade_no+" 订单金额："+total_amount+" 订单状态："+trade_status+" 下单时间:"+notify_time);

    }


}
